﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ServiceGUI.WorkBase;

namespace ServiceGUI
{
    public partial class MainPage : UserControl
    {
        private WorkBase.ServerClient _client;

        public MainPage()
        {
            InitializeComponent();
            _client = new WorkBase.ServerClient();

            this.Workground.Children.Add(new LoginControl(SetModeSetter, _client));
        }

        private void SetModeSetter(string login, string mode)
        {
            if (mode != null)
            {
                this.Workground.Children.Clear();

                switch (mode)
                {
                    case "user":
                        this.Workground.Children.Add(new UserViewControl(login, _client, OnUserLogout));
                        break;
                    case "admin":
                        this.Workground.Children.Add(new AdminControl(_client, OnUserLogout));
                        break;
                    default:
                        this.Workground.Children.Add(new UserViewControl(login, _client, OnUserLogout));
                        break;
                }
            }
        }

        private void OnUserLogout()
        {
            this.Workground.Children.Clear();
            this.Workground.Children.Add(new LoginControl(SetModeSetter, _client));
        }
    }
}
